<?php
/*
 * @Author: CHINAKAIYUAN<sunkaiyuan@namenode.cn>
 * @Date: 2022-02-03 00:33:05
 * @LastEditTime: 2023-09-18 17:17:22
 * @LastEditors: 孙开源 && sunkaiyuan@namenode.cn
 * @Description: BOM成品工艺辅料版别
 */

namespace App\Models;

use App\Traits\MaterialTrait;

class ProColorRev extends BaseModel
    {
    use MaterialTrait;

    public $timestamps = true;
    public $table = "basedata_pro_color_rev";
    protected $guarded = [];

    public function _creating($model)
        {
        $model->color_material_code = $model->main_id . "_" . $model->material_id;
        }
    public function _updating($model)
        {
        $model->color_material_code = $model->main_id . "_" . $model->material_id;
        }
    public function items()
        {
        return $this->hasMany(ProColorRevItem::class, "main_id")->orderBy('sort', 'asc');
        }
    public function status()
        {
        return $this->belongsTo(Dic::class, "status_id", "key")->where(function ($q)
            {
            $q->where("code", 'ColorTwoAudit');
            });
        }
    public function dyecraft()
        {
        return $this->belongsTo(ProDyecraft::class, "rscode", 'code');
        }
    public function dyebath()
        {
        return $this->belongsTo(Dic::class, "dyebath_id", "key")->where(function ($q)
            {
            $q->where("code", 'Dyebath');
            });
        }
    public function comp()
        {
        return $this->belongsTo(Dic::class, "comp_id", "key")->where(function ($q)
            {
            $q->where("code", 'Comp');
            });
        }
    public function main()
        {
        return $this->belongsTo(ProColor::class);
        }


    }
